/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.planning.tactical.wizard.common;

import org.openide.util.Utilities;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import junit.framework.Assert;
import java.awt.Component;
import javax.swing.JComboBox;
import nl.cloudfarming.client.planning.tactical.TacticalPlanningModule;
import nl.cloudfarming.client.planning.tactical.wizard.spray.BaseContextTest;
import nl.cloudfarming.client.planning.tactical.wizard.spray.PlanningWizardAction;
import org.openide.util.NbBundle;
import org.uispec4j.Panel;
import org.uispec4j.UISpec4J;
import org.uispec4j.finder.ComponentMatcher;
import static org.mockito.Mockito.*;

/**
 *
 * @author Merijn Zengers
 */

public class ActionTypeActionIT extends BaseContextTest{

    static {
        UISpec4J.init();
    }
    
    private final ComboBoxComponentMatcher comboBoxMatcher = new ComboBoxComponentMatcher();

    public void testPanel() {
        ActionTypeAction action = new ActionTypeAction();
        ActionEvent event = mock(ActionEvent.class);
        
        action.actionPerformed(event);
        
        Panel panel = new Panel(action.getPanel());
        
        Assert.assertTrue(panel.containsComponent(comboBoxMatcher).isTrue());
        String option = NbBundle.getMessage(TacticalPlanningModule.class, "action.wizard.choose.actiontype.combobox.option1");
        Assert.assertTrue(panel.getComboBox().contains(option).isTrue());
        
        
        Assert.assertNotNull(MockDialogDisplayer.options);
        Assert.assertTrue(MockDialogDisplayer.options[0] instanceof JButton);
        
        JButton okButton = (JButton) MockDialogDisplayer.options[0];
        
        for (ActionListener al : okButton.getActionListeners()) {
            al.actionPerformed(event);
        }
        
        Utilities.actionsGlobalContext().lookup(PlanningWizardAction.class);
  
    }

    class ComboBoxComponentMatcher implements ComponentMatcher {

        @Override
        public boolean matches(Component component) {
            return (component instanceof JComboBox);
        }
    }
    
}
